<template>
    <div>
        <div class="user-right">
            <div class="user-info">
                <div class="user-name-time">
                    <div class="time">{{ timestamp }}</div>
                    <div class="name">{{ senderUserID }}</div>
                </div>
                <div class="user-news">
                    <template v-if="type == 1">{{ message }}</template>
                    <img
                        v-if="type == 11"
                        :src="message"
                        alt=""
                        @click="previewImg([message])"
                    />
                    <img
                        v-if="type == 111"
                        :src="message"
                        alt=""
                        class="emoticon"
                    />
                    <div v-if="!isDetail && receiptStatus == 1" class="unread">
                        <div class="font">未读</div>
                    </div>
                    <div v-if="!isDetail && receiptStatus == 2" class="read">
                        <div class="font">已读</div>
                    </div>
                </div>
            </div>
            <div class="avatar" @click="goUser">
                <img class="img" :src="avatar" alt="" />
                <img
                    v-if="showV"
                    class="v"
                    src="~/assets/images/cswd/V.png"
                    alt=""
                />
            </div>
        </div>
        <div style="display: flex; justify-content: flex-end">
            <div v-if="quoteMsg" class="quote-msg">
                {{ quoteMsg.nickname }}：{{ quoteMsg.message }}
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: "chatList",
    props: {
        avatar: {
            type: String | Number,
            default: "https://api.xiaozhucaishui.com/assets/img/avatar.png",
        },
        senderUserID: {
            type: String | Number,
            default: "",
        },
        timestamp: {
            type: String | Number,
            default: "",
        },
        message: {
            type: String | Number,
            default: "",
        },
        type: {
            type: Number | String,
            default: 1,
        },
        showV: {
            type: Boolean,
            default: false,
        },
        UserID: {
            type: Number | String,
            default: "",
        },
        quoteMsg: {
            type: Object,
            default: null,
        },
        receiptStatus: {
            type: Number | String,
            default: 0,
        },
        isDetail: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {};
    },
    mounted() {
        // 滚动到聊天列表底部
        // this.scrollBottom();
    },
    methods: {
        previewImg(imgs) {
            this.$emit("previewImg", imgs);
        },
        goUser() {
            this.$router.push({
                path: "/cswd/user/" + this.UserID,
            });
        },
    },
};
</script>

<style lang="scss" scoped>
.user-left,
.user-right {
    margin-top: 1.8rem;
    display: flex;
}
.user-right {
    align-items: flex-start;
    justify-content: flex-end;
    .avatar {
        width: 2.5rem;
        height: 2.5rem;
        min-width: 2.5rem;
        position: relative;
        cursor: pointer;
        .img {
            width: 100%;
            height: 100%;
            overflow: hidden;
            border-radius: 60px;
            object-fit: cover;
        }

        .v {
            position: absolute;
            width: 0.8rem;
            height: 0.8rem;
            right: -1px;
            bottom: -2px;
        }
    }
    .user-info {
        margin-right: 16px;
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    .user-name-time {
        width: 100%;
        justify-content: flex-end;
    }
    .user-news {
        position: relative;
        white-space: pre-line;
        margin-left: 0;
        display: inline-block;
        background: #d3e9ff;
        border-radius: 4px;
        padding: 0.5rem 0.7rem;
        font-size: 14px;
        color: #333333;
        max-width: 14.28rem;
        position: relative;
        word-wrap: break-word;
        // &::before {
        //     content: "";
        //     width: 0px;
        //     height: 0px;
        //     border: 5px solid transparent;
        //     border-left-color: #d3e9ff;
        //     border-left-width: 8px;
        //     position: absolute;
        //     right: -12px;
        //     top: 15px;
        // }
        img {
            max-width: 7.5rem;
            width: auto;
            max-height: 5.62rem;
            object-fit: contain;
            cursor: pointer;
        }
        .emoticon {
            max-width: 168px;
            max-height: 126px;
        }
    }
}


.user-name-time {
    padding-bottom: 0.4rem;
    display: flex;
    align-items: flex-end;
    .name {
        font-size: 0.75rem;
        color: #999999;
    }
    .time {
        font-size: 0.75rem;
        padding: 0 0.2rem;
        font-weight: 300;
        color: #999999;
    }
}

.unread,
.read {
    position: absolute;
    width: 28px;
    height: 17px;
    bottom: -1px;
    left: -29px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    div {
        font-size: 14px;
        transform: scale(0.75);
        line-height: 17px;
    }
}

.unread {
    div {
        color: #409eff;
    }
}

.read {
    div {
        color: #909399;
    }
}
.quote-msg {
    padding-right: 76px;
    background-color: #e8e8e8;
    color: #99999c;
    padding: 4px 6px;
    border-radius: 4px;
    display: inline-block;
    font-size: 12px;
    margin-left: 76px;
    margin-top: 7px;
    max-width: 400px;
    -webkit-line-clamp: 2;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 20px;
}
</style>
